import Vue from 'vue';
import VueRouter from 'vue-router';
import VueI18n from 'vue-i18n';
import messages from '../module/about/lang';

import './base/init';

import Define from '../component/Define/Define.vue';
import LangPopover from '../component/LangPopover.vue';

import AboutUs from '../module/about/aboutUs/main';             // 关于我们
import ContactUs from '../module/about/contactUs/main';         // 联系我们
import Fees from '../module/about/fees/main';                   // 手续费
import PrivacyPolicy from '../module/about/privacyPolicy/main'; // 用户隐私
import UseTerms from '../module/about/useTerms/main';           // 使用协议
import SecurityPolicy from '../module/about/securityPolicy/main';           // 使用协议

let i18n =  new VueI18n({
    locale: window.app.LANG,
    messages, // set locale messages
});

const router = new VueRouter({
    'routes': [
        {
            path: '/',
            name: 'index',
            component: AboutUs
        },
        {
            path: '/about-us',
            name: 'about-us',
            component: AboutUs
        },
        {
            path: '/contact-us',
            name: 'contact-us',
            component: ContactUs
        },
        {
            path: '/fees',
            name: 'fees',
            component: Fees
        },
        {
            path: '/privacy-policy',
            name: 'privacy-policy',
            component: PrivacyPolicy
        },
        {
            path: '/use-terms',
            name: 'use-terms',
            component: UseTerms
        },
        {
            path: '/security-policy',
            name: 'security-policy',
            component: SecurityPolicy
        }
    ]
});

const app = new Vue({
    router,
    i18n,
    components: {
        Define,
        LangPopover
    },
    data() {
        return {
            title: ''
        };
    },
    created() {

    },
    mounted() {
        this.title = this.$refs.aboutUs.$el.innerText;
    },
    watch: {
        '$route.path'(newVal, oldVal) {
            this.updateTitle(newVal);
        }
    },
    methods: {
        updateTitle(route) {
            if (route.indexOf('about-us') >= 0) {
                this.title = this.$refs.aboutUs.$el.innerText;
            } else if (route.indexOf('contact-us') >= 0) {
                this.title = this.$refs.contactUs.$el.innerText
            } else if (route.indexOf('fees') >= 0) {
                this.title = this.$refs.fees.$el.innerText;
            } else if (route.indexOf('privacy-policy') >= 0) {
                this.title = this.$refs.privacyPolicy.$el.innerText;
            } else if (route.indexOf('use-terms') >= 0) {
                this.title = this.$refs.useTerms.$el.innerText;
            } else if (route.indexOf('security-policy') >= 0) {
                this.title = this.$refs.securityPolicy.$el.innerText;
            } else {
                this.title = this.$refs.aboutUs.$el.innerText
            }
        }
    }
}).$mount('#app');